<?php

/**
 * ProcessStatus 
 *
 * @author Administrator
 * @version
 */
class Model_Tables_AdminRolePriv extends Zend_Db_Table_Abstract {
    /**
     * The default table name
     */
    protected $_name = 'admin_role_priv';

    /**
     * delAdminRolePrivByProcessId()
     * 根据条件删除数据
     * @param  int $field where 条件
     * @param  int $value where 条件
     */
    public function delAdminRolePrivByProcessId( $field,$value)
    {
       $id  =$this->delete("field='$field' and value=$value");
    }
	
    /**
     * updateAdminRolePriv()
     * 更新方案步骤，根据$field,$value,$priv
     * @param Array $form 是post表单数据
     * @param  String $field 更新语句的where条件
     * @param  int $value 更新语句的where条件
     * @param  String $priv 更新语句的where条件
     */
 
	public function updateAdminRolePriv( $data ,$field,$value,$priv='')
    {
    	$this->delAdminRolePrivByProcessId($field,$value);
    	foreach($data as $k=>$v)
		{
			$p = array(
				'roleid' => $v,
				'field' => $field,
				'value'=>$value,
				'priv'=>$priv
			);
       		$this->insert($p);
		}
    }
    
    /**
     * getAdminRolePrivByProcessId()
     * 取符合条件的数据
     * @param  String $field 更新语句的where条件
     * @param  int $value 更新语句的where条件
     * @return String $ids ID列表(如：1,22,0)
     */
    
	public function getAdminRolePrivByProcessId($field,$value)
    {
    	$select = $this->select();
    	$select->from('admin_role_priv','roleid');
    	$select->where("field='$field' and value=$value");
    	
    	$result = $this->fetchAll($select);
    	$result=$result->toArray();
		
    	$ids ="";
        foreach ($result as $k => $v )
        {
        	$ids .=$v['roleid'].',';
        }
        
        $ids = $ids.'0';
        //echo '<pre>';print_r($ids);exit;
    	return $ids;
    }
}
